﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EA3.BusinessLogic;
using EntidadesNegocio;

/// <summary>
/// Summary description for SessionManagement
/// </summary>
public class SessionManagement
{
    private SessionManagement()
    {      

    }

    private static SessionManagement _intance;
    public static SessionManagement Instance()
    {
        if (_intance == null)
            _intance = new SessionManagement();
        return _intance;
    }

    public void SetSessionValue<T>(string lpKey, T lpValue)
    {
        if (HttpContext.Current.Session[lpKey] == null)
            HttpContext.Current.Session[lpKey] = lpValue;
    }

    public T GetSessionValue<T>(string lpKey)
    {
        return (T)HttpContext.Current.Session[lpKey];
    }

    public MailManager MailManager
    {        
        get {
            this.SetSessionValue<MailManager>("EmailMgr", new MailManager());
            return this.GetSessionValue<MailManager>("EmailMgr"); 
        }
    }

    public DataTable Menus
    {
        get {

            DataTable lvDtb = this.GetSessionValue<DataTable>("MenuTbl");

            if (lvDtb == null)
            {
                IProcedimientoAlmacenado lvProc = EntidadFabrica.CrearProcedimientoAlmacenado("usps_Menus", "Seguridad", Settings.Conexion);
                lvDtb = lvProc.EjecutarQuery().Tables[0];
                this.SetSessionValue<DataTable>("MenuTbl", lvDtb);
            }
             return lvDtb; 
        }
    }
}
